package com.nuoniu.sibanyun.service.po.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.bo.UnExecutedBo;
import com.nuoniu.sibanyun.entity.po.VPurchaseArrivalDetail;
import com.nuoniu.sibanyun.mapper.po.VPurchaseArrivalDetailMapper;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.po.IVPurchaseArrivalDetailService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 采购到货单明细表 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2020-11-19
 */
@Service
public class VPurchaseArrivalDetailServiceImpl extends ServiceImpl<VPurchaseArrivalDetailMapper, VPurchaseArrivalDetail> implements IVPurchaseArrivalDetailService {

    @Autowired
    private IErpAccountService accountService;

    @Override
    public void removeByOrderId(Long orderId) {
        baseMapper.removeByOrderId(orderId);
    }

    @Override
    public List<VPurchaseArrivalDetail> getOrderDetails(Long orderId) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id",userInfo.getCompanyId());
        queryWrapper.eq("order_id",orderId);
        List<VPurchaseArrivalDetail> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<UnExecutedBo> getRetUnExecuteQuantity(String inventoryIds,String warehouseIds) {
        Integer currentAccountId = accountService.getCurrentAccountId();
        UserInfo userInfo = UserThreadLocal.get();
        List<UnExecutedBo> retUnExecuteQuantityList = baseMapper.getRetUnExecuteQuantity(userInfo.getCompanyId(), currentAccountId, inventoryIds,warehouseIds);
        return retUnExecuteQuantityList;
    }

}
